//
//  CYBettingToolView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/18.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYBettingToolView.h"
@interface CYBettingToolView(){
    bettingToolBlock _myblock;
    UIColor *_lineColor;
}
@property (nonatomic, strong) CYButton *insertBtn;  //添加注单按钮
@property (nonatomic, strong) CYButton *bettingBtn; //快速下注按钮
@property (nonatomic, strong) CYLabel *moneyLBL;    //投注数目，金额
@property (nonatomic, strong) CYButton *randomBtn;   //机选
@end
@implementation CYBettingToolView
- (instancetype)initWithColor:(UIColor *)color line:(LineLayout)layout lineColor:(UIColor *)linecolor block:(bettingToolBlock)block{
    self = [super initWithColor:color line:layout lineColor:linecolor];
    if (self) {
        self.bettingNumber = @"0";
        self.money = @"0";
        _lineColor = linecolor;
        self.randomBtn.hidden = self.insertBtn.hidden = self.bettingBtn.hidden = NO;
        self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, AL(PT(100)));
        _myblock = block;

    }
    return self;
}

- (CYButton *)randomBtn{
    if (!_randomBtn) {
        _randomBtn = [[CYButton alloc]initWithTitle:@"机选" titleColor:ColorHex(0x333333) backgroundColor:[UIColor whiteColor] cornerRadius:0.0];
        [_randomBtn addTarget:self action:@selector(actionForRandomBtn) forControlEvents:UIControlEventTouchUpInside];
        [_randomBtn setTitleColor:ColorHex(0x888888) forState:UIControlStateHighlighted];
        _randomBtn.titleLabel.font = [UIFont systemFontOfSize:AL(PT(30))];
        _randomBtn.layer.borderWidth = 0.5;
        _randomBtn.layer.borderColor = _lineColor.CGColor;
        _randomBtn.layer.cornerRadius = 0.0;
        [self addSubview:_randomBtn];
        
        [_randomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0.0, 0.0, 0.0, SCREEN_WIDTH - AL(PT(100))));
        }];
    }
    return _randomBtn;
}

- (CYLabel *)moneyLBL{
    if (!_moneyLBL) { 
        _moneyLBL = [[CYLabel alloc]initWithText:nil size:AL(PT(30)) textcolor:ColorHex(0x333333)];
        _moneyLBL.textAlignment = NSTextAlignmentCenter;
        _moneyLBL.numberOfLines = 0;
        [self addSubview:_moneyLBL];
        
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0.0, AL(PT(100)) + 0.5, 0.0, SCREEN_WIDTH / 2.0));
        }];
    }
    return _moneyLBL;
}

- (CYButton *)insertBtn{
    if (!_insertBtn) {
        _insertBtn = [[CYButton alloc]initWithTitle:@"添加注单" titleColor:[UIColor whiteColor] backgroundColor:ColorHex(0xff5b05) cornerRadius:0.0];
        [_insertBtn addTarget:self action:@selector(actionForInsertBtn) forControlEvents:UIControlEventTouchUpInside];
        [_insertBtn setTitleColor:ColorHex(0x888888) forState:UIControlStateHighlighted];
        _insertBtn.titleLabel.font = [UIFont systemFontOfSize:AL(PT(30))];
        [self addSubview:_insertBtn];
        
        [_insertBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0.0, SCREEN_WIDTH / 2.0, 0.0, SCREEN_WIDTH / 4.0));
        }];
    }
    
    return _insertBtn;
}

- (CYButton *)bettingBtn{
    if (!_bettingBtn) {
        _bettingBtn = [[CYButton alloc]initWithTitle:@"快速下注" titleColor:[UIColor whiteColor] backgroundColor:THEME_COLOR cornerRadius:0.0];
        [_bettingBtn addTarget:self action:@selector(actionForBettingBtn) forControlEvents:UIControlEventTouchUpInside];
        [_bettingBtn setTitleColor:ColorHex(0x888888) forState:UIControlStateHighlighted];
        _bettingBtn.titleLabel.font = [UIFont systemFontOfSize:AL(PT(30))];
        [self addSubview:_bettingBtn];
        
        [_bettingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0.0, SCREEN_WIDTH / 4.0 * 3.0, 0.0, 0.0));
        }];
    }
    
    return _bettingBtn;
    
}

- (void)setMoney:(NSString *)money{
    if (_money != money)
        _money = money;
    if (_bettingNumber && _bettingNumber.length > 0)
        [self setupMoneyLBL];
}

- (void)setBettingNumber:(NSString *)bettingNumber{
    if (_bettingNumber != bettingNumber)
        _bettingNumber = bettingNumber;
    if (_money && _money.length > 0)
        [self setupMoneyLBL];
}

//设置投注数目和投注金额是特定的颜色，与字体
- (void)setupMoneyLBL{
    
    NSMutableAttributedString *attributedStr  = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"共%@注 %@元", _bettingNumber, _money]];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:AL(PT(28))] range:NSMakeRange(1, _bettingNumber.length)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:THEME_COLOR range:NSMakeRange(1, _bettingNumber.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:AL(PT(28))] range:NSMakeRange(3 + _bettingNumber.length, _money.length)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:THEME_COLOR range:NSMakeRange(3 + _bettingNumber.length, _money.length)];
    
    self.moneyLBL.attributedText = attributedStr;
    
}

- (void)actionForInsertBtn{
    _myblock(@"添加注单");
    
}

- (void)actionForBettingBtn{
    _myblock(@"快速下注");
}

- (void)actionForRandomBtn{
    _myblock(@"机选");
    
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
